package liecai_class.day06;

/**
 * 闭锁 CountDownLatch
 */
public class Demo03 {
    private static int count = 3;
    public static void main(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    synchronized (Demo03.class) {
                        System.out.println("弟弟买米回来了..");
                        count--;
                        Demo03.class.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                    synchronized (Demo03.class) {
                        System.out.println("姐姐买菜回来了..");
                        count--;
                        Demo03.class.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                    synchronized (Demo03.class) {
                        System.out.println("爸爸买锅回来了..");
                        count--;
                        Demo03.class.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        synchronized (Demo03.class){
            while(count>0){
                Demo03.class.wait();
            }
            System.out.println("妈妈开始做饭..");
        }
    }
}
